home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / QuickDraw / Out of This GWorld / Source / draw.c next >
Encoding:
C/C++ Source or Header  |  1996-09-17  |  5.1 KB  |  280 lines  |  [TEXT/CWIE]

  1. #include "out.h"
  2.  
  3. void shadeSCurve(int x, int y, int radout, int radin, int index);
  4. void drawColorSpheres(void);
  5.  
  6. void createColorScale()
  7. {
  8.     int i;
  9.     int x;
  10.     int down = true;
  11.     int    index = 8;
  12.  
  13.     PenSize( 14, 1 );
  14.     
  15.     for (x = -420; x < 420; x += 105)
  16.     {
  17.         for (i = 0; i < 30; i++)
  18.         {
  19.             setColor( index );
  20.             
  21.             if (down == true)
  22.                 drawLine( x, 420 - (i * 28) , x, 420 - ((i + 1) * 28) );
  23.             else
  24.                 drawLine( x, -420 + (i * 28) , x, -420 + ((i + 1) * 28) );
  25.             index++;
  26.         }
  27.         
  28.         down = 1 - down;
  29.     }
  30.     
  31.     down = false;
  32.     index = 8;
  33.  
  34.     for (x = 368; x > -472; x -= 105)
  35.     {
  36.         for (i = 0; i < 30; i++)
  37.         {
  38.             setColor( index );
  39.             
  40.             if (down == true)
  41.                 drawLine( x, 420 - (i * 28) , x, 420 - ((i + 1) * 28) );
  42.             else
  43.                 drawLine( x, -420 + (i * 28) , x, -420 + ((i + 1) * 28) );
  44.             index++;
  45.         }
  46.         
  47.         down = 1 - down;
  48.     }
  49. }
  50.  
  51. void createColorWheels()
  52. {
  53.     testTriangle( -400, 300 );
  54.     testTriangle( 400, 300 );
  55.     testTriangle( 400, -300 );
  56.     testTriangle( -400, -300 );
  57.     shadeWasher( 0, 0, 360, 80 );
  58. }
  59.  
  60. void createColorRings()
  61. {
  62.     shadeWasher( 0, 0, 500, 400 );
  63.     shadeWasher( 0, 0, 400, 300 );
  64.     shadeWasher( 0, 0, 300, 200 );
  65.     shadeWasher( 0, 0, 200, 100 );
  66. }
  67.  
  68. void createColorGears()
  69. {
  70.     shadeWasher( 150, 150, 300, 100 );
  71.     shadeWasher( -150, 150, 300, 100 );
  72.     shadeWasher( -150, -150, 300, 100 );
  73.     shadeWasher( 150, -150, 300, 100 );
  74. }
  75.  
  76. void createColorCurves()
  77. {
  78.     shadeWasher( 720, 720, 900, 0 );
  79.     shadeWasher( 720, -720, 900, 0 );
  80.     shadeWasher( -720, -720, 900, 0 );
  81.     shadeWasher( -720, 720, 900, 0 );
  82.     shadeWasher( 0, 0, 400, 0 );
  83. }
  84.  
  85. void createColorBalls()
  86. {
  87.     int x, y;
  88.  
  89.     for (x = -432; x <= 432; x += 108)
  90.         for (y = -432; y <= 432; y += 108)
  91.             shadeWasher( x, y, 60, 0 );
  92. }
  93.  
  94. void createColorWave()
  95. {
  96.     shadeSCurve( -300, 250, 210, 60, 9 );
  97.     shadeSCurve( 96, 250, 210, 60, 69 );
  98.     shadeSCurve( -300, 150, 210, 60, 129 );
  99.     shadeSCurve( 96, 150, 210, 60, 189 );
  100.     shadeSCurve( -300, 50, 210, 60, 9 );
  101.     shadeSCurve( 96, 50, 210, 60, 69 );
  102.     shadeSCurve( -300, -50, 210, 60, 129 );
  103.     shadeSCurve( 96, -50, 210, 60, 189 );
  104.     shadeSCurve( -300, -150, 210, 60, 9 );
  105.     shadeSCurve( 96, -150, 210, 60, 69 );
  106.     shadeSCurve( -300, -250, 210, 60, 129 );
  107.     shadeSCurve( 96, -250, 210, 60, 189 );
  108. }
  109.  
  110. void createColorText()
  111. {
  112.     Rect        rect;
  113.     PicHandle    thePict;
  114.     int            width, height;
  115.     
  116.     thePict = (PicHandle)GetResource( 'PICT', 129 );
  117.     
  118.     width = (**thePict).picFrame.right - (**thePict).picFrame.left;
  119.     height = (**thePict).picFrame.bottom - (**thePict).picFrame.top;
  120.  
  121.     SetRect( &rect, (WWIDTH - width) / 2, (WHEIGHT - height) / 2, 
  122.                     ((WWIDTH - width) / 2) + width, ((WHEIGHT - height) / 2 ) + height );
  123.  
  124.     DrawPicture( thePict, &rect );
  125.     ReleaseResource( (Handle)thePict );
  126. }
  127.  
  128. void drawColorSpheres()
  129. {
  130.     int rad;
  131.     int i;
  132.  
  133.     for (i = 9; i < 48; i++)
  134.     {
  135.         setColor( i );
  136.         rad = (48 - i) * 3;
  137.         drawCircle( (int)(i * 1.414), (int)(i * 1.414), rad );
  138.     }
  139. }
  140.  
  141. void testTriangle( x, y )
  142. int x, y;
  143. {
  144.     PenSize( 1, 1 );
  145.  
  146.     setColor( 7 );
  147.     drawCircle( x, y, 25 );
  148.  
  149.     setColor( 1 );
  150.     drawWasher( x, y, 25, 60, -30, 30 );
  151.     drawLine( x - 60, y + 40, x, y + 140 );
  152.     drawLine( x, y + 140, x + 60, y + 40 );
  153.     setColor( 2 );
  154.     drawWasher(x, y, 25, 60, 30, 90 );
  155.     setColor( 3 );
  156.     drawWasher(x, y, 25, 60, 90, 150 );
  157.     drawLine( x + 60, y + 40, x + 121, y - 70 );
  158.     drawLine( x + 121, y - 70, x, y - 70 );
  159.     setColor( 4 );
  160.     drawWasher( x, y, 25, 60, 150, 210 );
  161.     setColor( 5 );
  162.     drawWasher( x, y, 25, 60, 210, 270 );
  163.     drawLine( x - 60, y + 40, x - 121, y - 70 );
  164.     drawLine( x - 121, y - 70, x, y - 70 );
  165.     setColor( 6 );
  166.     drawWasher( x, y, 25, 60, 270, 330 );
  167. }
  168.  
  169. void shadeWasher( x, y, radout, radin )
  170. int x, y;
  171. int radout, radin;
  172. {
  173.     int ang;
  174.     int i = 8;
  175.     int radmid;
  176.  
  177.     radmid = radin + (radout - radin) / 2;
  178.     
  179.     for (ang = 0; ang < 360; ang += 3)
  180.     {
  181.         setColor( i );
  182.         drawWasher( x, y, radmid, radout, ang, ang + 3 );
  183.         i++;
  184.     }
  185.     
  186.     for (ang = 0; ang < 360; ang += 3)
  187.     {
  188.         setColor( i );
  189.         drawWasher( x, y, radin, radmid, ang, ang + 3 );
  190.         i++;
  191.     }
  192. }
  193.  
  194. void shadeSCurve( x, y, radout, radin, index)
  195. int x, y;
  196. int radout, radin;
  197. int index;
  198. {
  199. #pragma unused (radout)
  200. #pragma unused (radin)
  201.  
  202.     int ang;
  203.     
  204.     for (ang = 270; ang > 90; ang -= 6)
  205.     {
  206.         setColor( index );
  207.         drawWasher( x, y, 60, 210, ang, ang - 6 );
  208.         index++;
  209.     }
  210.  
  211.     for (ang = -90; ang < 90; ang += 6)
  212.     {
  213.         setColor( index );
  214.         drawWasher( x + 198, y, 60, 210, ang, ang + 6 );
  215.         index++;
  216.     }
  217. }
  218.  
  219. void translate( x, y )
  220. int *x, *y;
  221. {
  222.     int xx, yy;
  223.     
  224.     xx = *x / SCALE;
  225.     yy = *y / SCALE;
  226.     
  227.     *x = xx + (WWIDTH / 2);
  228.     *y = (-yy) + (WHEIGHT / 2);
  229. }
  230.  
  231. void scale( len )
  232. int *len;
  233. {
  234.     *len /= SCALE;
  235. }
  236.  
  237. void drawCircle( x, y, radius )
  238. int x, y;
  239. int radius;
  240. {
  241.     Rect     rect;
  242.     int        foo = 0;
  243.     
  244.     translate( &x, &y );
  245.     scale( &radius );
  246.  
  247.     SetRect( &rect, x - radius, y - radius, x + radius, y + radius );
  248.     PaintOval( &rect );
  249. }
  250.  
  251. void drawWasher( x, y, irad, orad, sang, eang )
  252. int x, y;
  253. int irad, orad;
  254. int sang, eang;
  255. {
  256.     int        width;
  257.     Rect    rect;
  258.     
  259.     translate( &x, &y );
  260.     scale( &irad );
  261.     scale( &orad );
  262.     
  263.     width = (orad - irad) / 2;
  264.     
  265.     PenSize( width, width );
  266.     SetRect( &rect, x - (irad + width), y - (irad + width),
  267.                     x + (irad + width), y + (irad + width) );
  268.                     
  269.     FrameArc( &rect, sang, eang - sang );
  270.     PenSize( 1, 1 );
  271. }
  272.  
  273. void drawLine( sx, sy, ex, ey )
  274. {    
  275.     translate( &sx, &sy );
  276.     translate( &ex, &ey );
  277.     
  278.     MoveTo( sx, sy );
  279.     LineTo( ex, ey );
  280. }